<template>
  <div style="min-width: 829px">
    <div v-if="$route.path == '/shopClassify'">
      <div class="vs-search-box">
        <el-form ref="form" :inline="true" :model="paging" label-width="110px">
          <el-form-item label="门店:">
            <el-input style="width: 200px" v-model="paging.title"></el-input>
          </el-form-item>
          <el-form-item label="负责人姓名">
            <el-input style="width: 200px" v-model="paging.name"></el-input>
          </el-form-item>
          <el-form-item label="" class="vs-right-btns">
            <el-button @click="reset">重置</el-button>
            <el-button @click="select(1)" type="primary">查询</el-button>
          </el-form-item>
          <el-form-item label="联系电话">
            <el-input style="width: 200px" v-model="paging.tel"></el-input>
          </el-form-item>
        </el-form>
      </div>
      <div class="vs-table-box">
        <div class="operation-box clear-float">
          <el-button
            icon="el-icon-plus"
            @click="utils.goUrl(`/editShop?title=新增门店`)"
            style="margin-left: auto"
            type="primary"
          >
            新增
          </el-button>
        </div>
        <el-table
          v-loading="loading"
          :data="tableData"
          header-row-class-name="has-gutter-table"
          style="width: 100%"
        >
          <el-table-column label="分类名称" prop="title"></el-table-column>
          <el-table-column prop="create_time" label="创建时间"> </el-table-column>
          <el-table-column prop="status" label="状态">
            <template slot-scope="scope">
              {{ scope.row.status == 1 ? "营业中" : "暂停营业" }}
            </template>
          </el-table-column>
          <el-table-column fixed="right" width="109" label="操作">
            <template slot-scope="scope">
              <span @click="setRow(1, scope.row)" class="tab-table-text">编辑</span>
              <span @click="setRow(2, scope.row)" class="tab-table-text">免单人管理</span>
              <span @click="setRow(3,scope.row)" class="tab-red-text">删除</span>
            </template>
          </el-table-column>
        </el-table>
        <div class="vs-paging-box">
          <el-pagination
            @current-change="handleCurrentChange"
            :current-page.sync="paging.page"
            :page-size="paging.limit"
            layout="prev, pager, next, jumper"
            :total="paging.total"
          >
          </el-pagination>
        </div>
      </div>
    </div>
    <router-view></router-view>
  </div>
</template>

<script>
export default {
  data() {
    return {
      loading: false,
      paging: {
        title: "",
        name: "",
        tel: "",
        page: 1,
        limit: 10,
        total: 0, //总数
      },
      tableData: [],
    };
  },
  created() {
    this.GetList();
  },
  methods: {
    handleCurrentChange(val) {
      this.paging.page = val;
      this.GetList();
    },
    // 查询
    select() {
      if (!this.paging.title && !this.paging.name && !this.paging.tel) {
        this.utils.message("查询条件至少输入一项！");
        return false;
      }
      this.GetList();
    },
    async setRow(type, row) {
        if (type == 1) {
            this.utils.goUrl(`/editShop?title=门店编辑&id=${row.id}`);
        }else if(type == 2) {
            this.utils.goUrl(`/freeofcharge?id=${row.id}`)
        }else{
            this.$msgbox({
                title: '提示',
                message: '确定要删除该门店吗?',
                type: 'warning',
                showCancelButton: true,
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                beforeClose:async (action, instance, done) => {
                    if (action === 'confirm') {
                    instance.confirmButtonLoading = true;
                    instance.confirmButtonText = '执行中...';
                    let {code,data} = await this.$Http.delStore({id:row.id})
                        if(code){
                            this.$message.success('删除成功!');
                            this.handleCurrentChange(1)
                        }
                        done();
                        instance.confirmButtonLoading = false;
                    } else {
                        done();
                    }
                }
            }).then(action => {

            }).catch(()=>{});
        }
    },
    // 获取分类列表
    async GetList() {
      this.loading = true;
      let { code, data } = await this.$Http.getStoreCate(this.paging);
      this.loading = false;
      if (code) {
        if (data.data.length) {
          data.data.forEach((ele) => {
            let end_time = ele.end_time.split(":");
            let start_time = ele.start_time.split(":");
            ele.end_time = end_time[0] + ":" + end_time[1];
            ele.start_time = start_time[0] + ":" + start_time[1];
          });
        }
        this.tableData = data.data;
        this.paging.limit = data.per_page;
        this.paging.total = data.total;
      }
    },
    reset() {
      //重置
      this.paging = this.$options.data().paging;
      this.GetList();
    },
  },
};
</script>

<style lang="scss" scoped>
.image-thumbnail {
  width: 130px;
  height: 130px;
}
</style>